package com.umeox.watch.moto.dataservice

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun uninstall(view: View) {
        //UninstallApk()
    }


    private fun UninstallApk() {
        val packageName = "com.hubbleconnected.mimo.fourcolours"
        Log.d("TAG", "UninstallApk: $packageName")
        val packageURI: Uri = Uri.parse("package:$packageName")
        val uninstallIntent = Intent(Intent.ACTION_DELETE, packageURI)
        startActivityForResult(uninstallIntent, 100)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        Log.d(
            "TAG",
            "requestCode:$requestCode, resultCode:$resultCode"
        )
        when (requestCode) {
            1 -> if (resultCode == RESULT_OK) {
                Log.d("TAG", "onActivityResult: executed") //点击确定，为什么打印此行？？
            } else {
                Log.d("TAG", "onActivityResult: executed in here**") //点击取消，打印此行。
            }
            else -> {}
        }
    }

}